//
//  HWHomeBannerProtocol.swift
//  HWanGame
//
//  Created by 王昌健 on 2021/12/27.
//  Copyright © 2021 94Wan. All rights reserved.
//

import UIKit

class HWHomeBannerProtocol: UICollectionViewCell {
    var model:HWHomeModel?
    var scrollDidScroll:((_:UIScrollView)->())?
    var didClickItem:((_:HWHomeGongNengModel)->())?
}

extension HWHomeBannerProtocol:UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout {
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        self.didClickItem?(model?.gongneng?[indexPath.row] ?? HWHomeGongNengModel())
    }
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
        return 9*widthScale
    }
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
        return 0
    }
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        return CGSize(width: screenWidth/5, height: 65*widthScale)
    }
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return  model?.gongneng?.count ?? 0
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let itemCell = collectionView.dequeueReusableCell(withReuseIdentifier: "HWHomeBannerItemCell", for: indexPath) as! HWHomeBannerItemCell
        itemCell.model = model?.gongneng?[indexPath.row]
        return itemCell
        
    }
    
    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        self.scrollDidScroll?(scrollView)
    }
    
}
